package icegps.com.pingdj;


import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.tencent.bugly.crashreport.CrashReport;


import icegps.com.pingdj.data.ble.BleHelper;
import icegps.com.pingdj.gen.DaoMaster;
import icegps.com.pingdj.gen.DaoSession;
import icegps.com.pingdj.utils.Utils;
import timber.log.Timber;

/**
 * Created by 111 on 2018/2/25.
 */

public class App extends Application {
    private static App app;
    private String serviceUUID = "0000f1f0-0000-1000-8000-00805f9b34fb";
    private String writeUUID = "0000f1f1-0000-1000-8000-00805f9b34fb";
    private String notifyUUID = "0000f1f2-0000-1000-8000-00805f9b34fb";
    private DaoMaster.DevOpenHelper devOpenHelper;
    private SQLiteDatabase db;
    private DaoMaster daoMaster;
    private DaoSession daoSession;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        Timber.plant(new Timber.DebugTree());
        BleHelper.init(notifyUUID, writeUUID, serviceUUID, app);
        Utils.init(this);
        setDatabase();
        CrashReport.initCrashReport(getApplicationContext(), "f1a1777a5d", false);

    }


    public static App getInstance() {
        return app;
    }

    public int getWindowHeight() {
        return getResources().getDisplayMetrics().heightPixels;
    }

    public int getWindowWidth() {
        return getResources().getDisplayMetrics().widthPixels;
    }

    public int getMemoryCacheSize() {
        ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        int largeMemoryClass = activityManager.getLargeMemoryClass();
        return largeMemoryClass * 1024 * 1024 / 8;
    }

    private void setDatabase() {
        devOpenHelper = new DaoMaster.DevOpenHelper(this, "mmp-db", null);
        db = devOpenHelper.getWritableDatabase();
        daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();
    }

    public DaoSession getDaoSession() {
        return daoSession;
    }

}
